using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Threading;
using ISXWoW;
using LavishVMAPI;
using InnerSpaceAPI;

namespace ISXUGAuction
{
    class UGMailCmd
    {
        /* UGMailCmd by UndRgrnD59(undrgrnd59@gmail.com)
         * =============================================
         * This contains all the commands your going to
         * want to use with mail. It's hard to tell if 
         * it works really well, because sometimes the 
         * mailbox lags and you can't get it - and I'm
         * not sure if its the program or the lag spike.
         * ============================================= */

        #region Advanced Mail Commands

        public List<UGMail> RetrieveMailList()
        {
            List<UGMail> returnList = new List<UGMail>();

            int mailAmmount = GetMailAmmount();
            for (int i = 1; i < mailAmmount + 1; i++)
            {
                UGMail temp = GetMailMessage(i);
                returnList.Add(temp);
            }

            return returnList;
        }

        #endregion

        #region Simple Mail Commands

        public bool HasMail()
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();
            string newMail = isxwow.WoWScript<string>("HasNewMail()");
            if (newMail == "1")
                return true;
            return false;
        }

        public UGMail GetMailMessage(int index)
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();

            // gather the information about the indexed mail
            string sender = isxwow.WoWScript<string>("GetInboxHeaderInfo(" + index + ")", 3);
            string subject = isxwow.WoWScript<string>("GetInboxHeaderInfo(" + index + ")", 4);
            int money = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 5);
            int CODAmmount = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 6);
            double daysleft = isxwow.WoWScript<double>("GetInboxHeaderInfo(" + index + ")", 7);
            int hasItem = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 8);
            int wasRead = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 9);
            int wasReturned = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 10);
            int textCreated = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 11);
            int canReply = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 12);
            int isGM = isxwow.WoWScript<int>("GetInboxHeaderInfo(" + index + ")", 13);

            return new UGMail(index, sender, subject, money, CODAmmount, daysleft, hasItem, wasRead, wasReturned, textCreated, canReply, isGM);
        }

        public void TakeInboxItem(int index)
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();
            isxwow.WoWScript("TakeInboxItem(" + index + ")");
        }

        public void TakeInboxMoney(int index)
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();
            isxwow.WoWScript("TakeInboxMoney(" + index + ")");
            Thread.Sleep(4000); // 4 seconds to grab money
        }

        public void DeleteInboxItem(int index)
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();



            isxwow.WoWScript("DeleteInboxItem(" + index + ")");
        }

        public void CheckMail()
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();
            isxwow.WoWScript("CheckInbox()"); // updates the mailbox
        }

        public int GetMailAmmount()
        {
            ISXWoW.ISXWoW isxwow = new ISXWoW.ISXWoW();
            return isxwow.WoWScript<int>("GetInboxNumItems()");
        }

        #endregion
    }
}
